using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwDeferredRS
{
    /// <summary>
    /// A simple base map feature
    /// </summary>
    public class LightMapFusion : AbstractFusion
    {
        public LightMapFusion()
        {
            AddPreprocessor(new Preprocessor("LIGHTMAP_UV", 1, 3, 1, "UV channel (1-3) for lightMap."));

            // param lightMap
            AddParameter(
                new Texture2dParamter("lightMap", "lightMapSamp")
                .SetUserData("fragment")
                .SetSRGBTexture(false)
                );

            // param lightMapMultiplier
            AddParameter(
                new ScalarParameter("lightMapMultiplier")
                .SetS(1.0f)
                .SetDesc("Scale the intensity of the light map")
                );
        }

        public override string Name
        {
            get { return "LightMap"; }
        }

        public override string Desc
        {
            get { return "Enable this fusion to support static lightings."; }
        }

        public override Stage Stage
        {
            get { return Stage.Illumination; }
        }

        public override int UVChannelCount
        {
            get { return GetPreprocessor("LIGHTMAP_UV").Value; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "vec4 lightMap = tex2D(lightMapSamp, pipeline.Texcoord[LIGHTMAP_UV-1]);");
            AddLine(b, "pipeline.Illumination += lightMap.rgb * lightMapMultiplier;");
        }
    }
}